package cn.esale.action;

import java.math.BigDecimal;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cn.esale.entity.SaleOrder;
import cn.esale.entity.SaleOrderLine;
import cn.esale.entity.SaleProduct;
import cn.esale.service.CusCustomerBiz;
import cn.esale.service.OrderBiz;
import cn.esale.service.ProductBiz;

public class OrderAction extends ActionSupport {
	private SaleOrder item;
	
	private SaleOrderLine line;
	
	private OrderBiz orderBiz= null;
	
	private CusCustomerBiz cusCustomerBiz = null;
	
	private ProductBiz productBiz = null;
	
	public SaleOrderLine getLine() {
		return line;
	}

	public void setLine(SaleOrderLine line) {
		this.line = line;
	}

	public ProductBiz getProductBiz() {
		return productBiz;
	}

	public void setProductBiz(ProductBiz productBiz) {
		this.productBiz = productBiz;
	}

	public CusCustomerBiz getCusCustomerBiz() {
		return cusCustomerBiz;
	}

	public void setCusCustomerBiz(CusCustomerBiz cusCustomerBiz) {
		this.cusCustomerBiz = cusCustomerBiz;
	}

	public SaleOrder getItem() {
		return item;
	}

	public void setItem(SaleOrder item) {
		this.item = item;
	}

	public OrderBiz getOrderBiz() {
		return orderBiz;
	}

	public void setOrderBiz(OrderBiz orderBiz) {
		this.orderBiz = orderBiz;
	}
	
	public String toAdd ()throws Exception{
		return SUCCESS;
	}
	public String doAdd()
			throws Exception{
		this.orderBiz.add(this.getItem());
		ActionContext ac=ActionContext.getContext();
		ac.getSession().put("id", item.getOdrId());
		return "addDetail";
	}
	public String toAddDetail()throws Exception{
		ActionContext ac=ActionContext.getContext();
		

		BigDecimal a=(BigDecimal) ac.getSession().get("id");
		Long orderId = a.longValue();
		this.item = this.orderBiz.getWithLines(orderId);
		
		List<SaleProduct> product = productBiz.findAll();
		ac.put("prodList",product);
		return INPUT;
	}
	
	public String doAddDetail()throws Exception{
		this.orderBiz.addDetail(line);
		ActionContext ac=ActionContext.getContext();
	
		return "addDetail";
	}
}
